package com.xiaoniu.timer;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.UUID;

/**
 * Created by sweet on 17-9-7.
 */
public class TimerUtilsHelp {

//  public static void main(String[] args) throws ParseException {
//    dateToMillisecond("2017-10-8 10:01");
//    System.out.println("==================");
//    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
//    Date parse = simpleDateFormat.parse("2017-10-8 10:01");
//    System.out.println(parse.getTime());
//
//    System.out.println(year() + "-" + month() + "-" + day());
//  }

  /**
   * 生成 2017/10/01 路径
   * @return
   */
  public static String dir() {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    return simpleDateFormat.format(new Date());
  }

  /**
   * 当前时间戳
   * @return
   */
  public static String time() {
    return System.currentTimeMillis()+"";
  }

  public static long stringToMillisecond(String s) {
    return Long.parseLong(s) * 60 * 1000L;
  }

  public static long dateToMillisecond(String date) throws ParseException {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    Date parse = simpleDateFormat.parse(date);
    return parse.getTime();
  }

  public static String formatDate(long l) {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    Date date = new Date(l);
    return simpleDateFormat.format(date);
  }

  public static Integer year() {
    return LocalDateTime.now().getYear();
  }

  public static Integer month() {
    return LocalDateTime.now().getMonth().getValue();
  }

  public static Integer day() {
    return LocalDateTime.now().getDayOfMonth();
  }

  public static Integer maxDay() {
    return LocalDateTime.now().getMonth().maxLength();
  }

  /**
   * 大写 uuid
   * @return
   */
  public static String uuid() {
    return UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
  }

  /**
   * 获取文件的类型
   * @param name
   * @return
   */
  public static String type(String name) {
    return name.substring(name.lastIndexOf(".")+1, name.length());
  }
}
